import 'package:flutter/cupertino.dart';
import 'package:flutter_deer/index/iview/historical_expenditure_list_iview.dart';
import 'package:flutter_deer/index/models/com_code_entity.dart';
import 'package:flutter_deer/index/models/historical_expenditure_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/res/constant.dart';

class HistoricalExpenditureListPagePresenter
    extends BasePagePresenter<HistoricalExpenditureListIMvpView> {
  HistoricalExpenditureListPagePresenter();

  @override
  void initState() {}

  Future<dynamic> getHistoricalExpenditureList(String? fiscalYear, String? agencyName,  String? depBgtEcoName, String? fundTypeName,  String? expFuncName, String? govBgtEcoName) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['fiscal_year'] = fiscalYear;
      params['agency_name'] = agencyName;
      params['dep_bgt_eco_name'] = depBgtEcoName;
      params['fund_type_name'] = fundTypeName;
      params['exp_func_name'] = expFuncName;
      params['gov_bgt_eco_name'] = govBgtEcoName;
      params['page_size'] = Constant.pageSize;
      params['current'] = 1;
      asyncRequestNetwork<BaseEntity<HistoricalExpenditurePageEntity>>(Method.get,
          url: HttpApi.historicalExpenditurePageFundTypeList,
          queryParameters: params, onSuccess: (data) {
        view.setHistoricalExpenditurePage(data!.data);
      }, onError: (code, msg) {});
    });
  }

  Future<dynamic> getMoreIndentList(String? fiscalYear, int? pageNo) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, dynamic> params = <String, dynamic>{};
      params['fiscal_year'] = fiscalYear;
      params['page_size'] = Constant.pageSize;
      params['current'] = pageNo;
      asyncRequestNetwork<BaseEntity<HistoricalExpenditurePageEntity>>(Method.get,
          url: HttpApi.historicalExpenditurePageFundTypeList,
          queryParameters: params, onSuccess: (data) {
        view.setHistoricalExpenditurePage(data!.data);
      }, onError: (code, msg) {});
    });
  }

    Future<dynamic> getFundTypeList(String fund_type_name) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, String> params = <String, String>{};
      params['fund_type_name'] = fund_type_name;
      asyncRequestNetwork<BaseEntity<List<CodeMapEntity>>>(Method.get,
          url: HttpApi.getFundTypeMapList,
          queryParameters: params, onSuccess: (data) {
        view.setFundTypeListPage(data!.data);
      }, onError: (code, msg) {
        print('onErrorxxxxxxxxxxxxxxxxsdd');
      });
    });
  }

  Future<dynamic> getDepBgtEcoList(String dep_bgt_eco_name) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, String> params = <String, String>{};
      params['dep_bgt_eco_name'] = dep_bgt_eco_name;
      asyncRequestNetwork<BaseEntity<List<CodeMapEntity>>>(Method.get,
          url: HttpApi.getDepBgtEcoMapList,
          queryParameters: params, onSuccess: (data) {
        view.setDepBgtEcoListPage(data!.data);
      }, onError: (code, msg) {});
    });
  }

  Future<dynamic> getGovBgtEcoList(String gov_bgt_eco_name) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, String> params = <String, String>{};
      params['gov_bgt_eco_name'] = gov_bgt_eco_name;
      asyncRequestNetwork<BaseEntity<List<CodeMapEntity>>>(Method.get,
          url: HttpApi.getGovBgtEcoMapList,
          queryParameters: params, onSuccess: (data) {
        view.setGovBgtEcoListPage(data!.data);
      }, onError: (code, msg) {});
    });
  }

  Future<dynamic> getExpFuncList(String exp_func_name) async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final Map<String, String> params = <String, String>{};
      params['exp_func_name'] = exp_func_name;

      asyncRequestNetwork<BaseEntity<List<CodeMapEntity>>>(Method.get,
          url: HttpApi.getExpFuncMapList,
          queryParameters: params, onSuccess: (data) {
        view.setExpFuncListPage(data!.data);
      }, onError: (code, msg) {});
    });
  }
}
